<?php
/* See
      http://themeshaper.com/blog/functions-php-wordpress-child-themes/
   and 
      http://icfun.blogspot.com/2008/07/php-how-to-check-useragent.html
   and 
      http://justintadlock.com/archives/2007/11/01/wordpress-custom-fields-listing-a-series-of-posts
   for more */


/* NOTE ie fix has stopped working. Odd */

function childtheme_iefix() { 

    ?> <!--[if IE]>
            <link rel="stylesheet" type="text/css" href="<?php echo bloginfo('stylesheet_directory') ?>/ie.css" />
       <![endif]-->
            <?php
}

function childtheme_specialcss() { 
	/* This is to provide over-ride CSS which is date/time specific, note, will over-ride MSIE sheet */
	?><link rel="stylesheet" type="text/css" href="<?php echo bloginfo('stylesheet_directory') ?>/specialdates.css" />
<?php }
 


function childtheme_variantcss() {
     $variantcss_path = WP_CONTENT_DIR.'/themes/murkymatic/variantpermanent.css';
     $variantcss_url = WP_CONTENT_URL.'/themes/murkymatic/variantpermanent.css';
     if (file_exists($variantcss_path)) { ?>   
          <!-- Custom CSS -->
          <link rel="stylesheet" type="text/css" href="<?php bloginfo('wpurl'); ?>/wp-content/themes/murkymatic/variantpermanent.css" />      	
    	
     <?php } elseif (file_exists($variantcss_url)) { ?>   
          <!-- Custom CSS -->
          <link rel="stylesheet" type="text/css" href="<?php bloginfo('wpurl'); ?>/wp-content/themes/murkymatic/variantpermanent.css" />
     <?php } else { ?> <!-- Create the file variantpermanent.css in the murkymatic directory to customise things --> <?php }
    if(isset($_SERVER['HTTP_USER_AGENT'])){
        $agent = $_SERVER['HTTP_USER_AGENT'];
        if(strstr($agent,'MSIE')){
            ?>
            <!-- Variant.css disabled for MSIE as I didn't want the hassle of making MSIE compatible temporary stylings -->
            <?php
        } else {
            // Pre-2.6 compatibility
            if ( !defined('WP_CONTENT_URL') )
                define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content');
            if ( !defined('WP_CONTENT_DIR') )
                define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
    
            // Guess the location
            $variantcss_path = WP_CONTENT_DIR.'/themes/murkymatic/variant.css';
            $variantcss_url = WP_CONTENT_URL.'/themes/murkymatic/variant.css';

            if (file_exists($variantcss_path)) { ?>   
                <!-- Custom CSS -->
            	<link rel="stylesheet" type="text/css" href="<?php bloginfo('wpurl'); ?>/wp-content/themes/murkymatic/variant.css" />      	
    	
            <?php } elseif (file_exists($variantcss_url)) { ?>   
                <!-- Custom CSS -->
            	<link rel="stylesheet" type="text/css" href="<?php bloginfo('wpurl'); ?>/wp-content/themes/murkymatic/variant.css" />
            <?php } else { ?> <!-- Create the file variant.css in the murkymatic directory to customise things --> <?php }	
        }

    }  

} 



// custom login for theme
function childtheme_custom_login() {
	echo '<link rel="stylesheet" type="text/css" href="' . get_bloginfo('stylesheet_directory') . '/customlogin.css" />';
}

// custom admin theme
function childtheme_admin() {
	echo '<link rel="stylesheet" type="text/css" href="' . get_bloginfo('stylesheet_directory') . '/adminstyling.css" />';
}

function childtheme_custom_loginmessage() {
	echo '<p class="murkymaticmessage"><a href="http://www.murky.org/blg/murkymatic/">Murkymatic</a> is a <a href="http://themeshaper.com/blog/functions-php-wordpress-child-themes/">Child Theme</a> in the <a href="http://themeshaper.com/thematic-for-wordpress/">Thematic Framework</a></p>';
}


function childtheme_article_footer($footer) {
	$extra_stuff='';

	global $id, $post;
	$series = get_post_meta($post->ID, 'Series', true);
	$pstlink = get_permalink();
	$psttitle = get_the_title();
	$pstbody = get_the_excerpt();
	if($series) :
		$args = array(
			'numberposts' => -1,
			'meta_key' => 'Series',
			'meta_value' => $series,
		);
		$series_posts = get_posts($args);
		if($series_posts) :
			$class = preg_replace("/[^a-z0-9\\040\\.\\-\\_\\\\]/i", "", $series);
			$class = strtolower(str_replace(array(' ', ' '), '-', $class));
			if (is_single()) {
				$extra_stuff = '<div class="series series-' . $class . '"><h4 class="series-title">' . __('Articles in this series') . '</h4><ul>';
				foreach($series_posts as $serial) :
					if($serial->ID == $post->ID)
						$extra_stuff = $extra_stuff . '<li class="current-post">' . $serial->post_title . '</li>';
					else
					$extra_stuff = $extra_stuff .  '<li><a href="' . get_permalink($serial->ID) . '" class="postID_' . $serial->ID . '" title="' . str_replace('"', '"', $serial->post_title) . '">' . str_replace('"', '"', $serial->post_title) . '</a></li>';
				endforeach;
				$extra_stuff = $extra_stuff .  '</ul></div>';
			} else { 
                                $extra_stuff = $extra_stuff .  '<div class="series series-' . $class . '">';
                                $extra_stuff = $extra_stuff .  '<h4 class="series-title"><a href="' . $pstlink . '">' . $psttitle . '</a>';
                                $extra_stuff = $extra_stuff .  ' is part of a series' . '</h4></div>'; 
                        }  
		endif;
	endif;
	$pageurl = get_bloginfo('siteurl');
        $pageurl = $pageurl . "?p=" . $post->ID;
	$extra_stuff_post = '<div class="socialnetwork"><ul>';
	$extra_stuff_post = $extra_stuff_post . '<li>Send to: <a class="twitterlink" href="http://twitter.com/home?status=Currently reading ' . $pageurl . '" title="Click to send ' . $psttitle . ' to Twitter!" target="_blank">Twitter</a></li>';
	$extra_stuff_post = $extra_stuff_post . '<li><a class="deliciouslink" href="http://del.icio.us/post?url=' . $pstlink . '&title=' . $psttitle . '" title="Click to bookmark ' . $psttitle . ' on del.icio.us!" target="_blank">del.icio.us</a></li>';
	$extra_stuff_post = $extra_stuff_post . '<li><a class="digglink" href="http://digg.com/submit?phase=2&url=' . $pstlink . '&title='. $psttitle . '&bodytext=' . $pstbody . '" title="Click to bookmark ' . $psttitle . ' on Digg!" target="_blank">Digg</a></li>';
	$rss_url = get_bloginfo('rss2_url');
	$extra_stuff_post = $extra_stuff_post . '<li>Use the: <a class="rsslink" href="' . $rss_url . '" title="Click to Subscribe to the Feed"  rel="alternate" type="application/rss+xml" target="_blank">RSS Feed</a></li>';
	$extra_stuff_post = $extra_stuff_post . '</ul></div>';
	$footer = $extra_stuff . $footer . $extra_stuff_post;
	return $footer;
}


add_action('thematic_postfooter','childtheme_article_footer');
add_action('login_form', 'childtheme_custom_loginmessage'); 
add_action('login_head', 'childtheme_custom_login');
add_action('wp_head', 'childtheme_iefix');
add_action('wp_head', 'childtheme_specialcss');
add_action('wp_head', 'childtheme_variantcss');
add_action('admin_head', 'childtheme_admin');
?>
